<template>
  <v-card>
    <v-alert
      class="success"
      type="success"
      dense
      :value="err"
      border="top"
    >
      保存成功
    </v-alert>
    <v-card-title class="mb-2">
      <div class="item">
        <!-- <document-action-menu /> -->
        <check-button
          @succ="succ"
          @refresh="refresh"
          class="ms-2"
        ></check-button>
        <check-button-back
          @erro="erro"
          @refresh="refresh"
          class="ms-2"
          :qualityItems="qualityItems"
        ></check-button-back>
        <!--
        <delete-button
          @succ="succ"
          @refresh="refresh"
          class="ms-2"
        ></delete-button>
        -->
        <date-picker @query="query" @update="update" :searchReturnData="searchReturnData"></date-picker>
        <!-- <a-selects @changeResult="changeResult" class="quality"></a-selects> -->
      </div>
    </v-card-title>
    <!-- <document-list /> -->
    <atable
      :startTimeData="startTimeData"
      :refreshData="refreshData"
      :result="result"
      :backTotal="backTotal"
      :initialData="initialData"
      :queryItem="queryItem"
      @searchData="searchData"
    ></atable>
  </v-card>
</template>

<script>
// import DocumentService from '@/services/document.service'
import { mapState } from 'vuex'
// import DocumentList from '@/components/containers/documents/DocumentList'
// import DocumentActionMenu from '@/components/containers/documents/DocumentActionMenu'
import checkButton from './check-button.vue'
import checkButtonBack from './check-button-back.vue'
import DatePicker from './date-picker.vue'
import atable from './atable.vue'
// import DeleteButton from './delete-button.vue'
// import ASelects from './selects.vue'
export default {
  layout: 'project',
  // async fetch() {
  //   const data = await DocumentService.getQualityItems({
  //     projectId: this.$route.params.id,
  //     ...this.$route.query
  //   })
  //   this.initialData = data.data.results
  //   console.log(this.initialData)
  //   this.backTotal = data.data.count
  //   console.log(this.backTotal)
  // },
  data() {
    return {
      roleName: null,
      startTimeData: null,
      success: null,
      err: false,
      refreshData: [],
      result: [],
      backTotal: null,
      initialData: [],
      queryItem: [],
      searchReturnData: ''
    }
  },
  computed: {
    ...mapState('documents', [
      'items',
      'qualityItems',
      'qualitySelected',
      'loading',
      'total'
    ]),
    ...mapState('members', ['items', 'selected', 'loading'])
  },
  components: {
    // DocumentList,
    // DocumentActionMenu,
    atable,
    checkButton,
    checkButtonBack,
    DatePicker
    // DeleteButton
  },

  validate({ params, query }) {
    return (
      /^\d+$/.test(params.id) &&
      /^\d+|$/.test(query.limit) &&
      /^\d+|$/.test(query.offset)
    )
  },
  // 创建判断用户权限 是否满足状态 传递给 button是否存在
  created() {
    this.roleName = localStorage.getItem('userId')
  },
  methods: {
    searchData(data) {
      // 2021.8.30 互相接口添加search参数
      this.searchReturnData = data
      console.log(this.searchReturnData)
    },
    query(data) {
      this.queryItem = data
    },
    changeResult(data) {
      this.result = data[0]
      this.backTotal = data[1]
    },
    refresh(data) {
      this.refreshData = data
    },
    update(data) {
      this.startTimeData = data.data.results
    },
    erro(data) {
      if (data === 200) {
        this.err = true
        this.success = 'success'
        setTimeout(() => {
          this.err = false
        }, 1500)
      }
    },
    succ(data) {
      if (data === 200) {
        this.err = true
        this.success = 'success'
        setTimeout(() => {
          this.err = false
        }, 1500)
      }
    }
  }
}
</script>
<style scoped>
.item {
  width: 100vw;
  display: flex;
  align-items: center;
}
.success {
  position: absolute;
  z-index: 999999;
  top: 20%;
  left: 35%;
}
.quality {
  width: 50%;
}
</style>
